package com.xf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xf.common.core.domain.DmpResult;
import com.xf.common.core.entity.QueryRequest;
import com.xf.common.core.entity.dmp.DmpOrganization;
import com.xf.service.OrganizationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 组织
 *
 * @author JoeyLiu
 * @create 2022-04-24 17:42
 */

@Slf4j
@Validated
@RestController
@RequestMapping("organization")
public class OrganizationController {
    @Resource
    private OrganizationService organizationService;


    @GetMapping("/getPage")
    public DmpResult<IPage<DmpOrganization>> list(QueryRequest request, DmpOrganization organization) {
        return DmpResult.data(organizationService.getPage(request, organization));
    }

    /**
     * 创建工作空间
     *
     * @param tenant
     * @return
     */
    @PostMapping("/add")
    public DmpResult createWorkspace(@Valid DmpOrganization tenant) {
        organizationService.create(tenant);
        return DmpResult.success();
    }

    /**
     * 修改工作空间信息
     *
     * @param tenant
     * @return
     */
    @PutMapping("/update")
    public DmpResult updateWorkspace(@Valid DmpOrganization tenant) {
        organizationService.updateById(tenant);
        return DmpResult.success();

    }

    /**
     * 删除工作空间信息
     *
     * @param tenantId 工作空间id
     * @return
     */
    @DeleteMapping("/delete")
    public DmpResult updateWorkspace(@RequestParam("tenantId") String tenantId) {
        organizationService.removeById(tenantId);
        return DmpResult.success();

    }
}
